﻿
Imports System.Text

Public Module _error_handle
    Public Function patchup_error_msg(ByVal m() As Object) As String
        k_assert(Not m Is Nothing)
        Dim s As StringBuilder = Nothing
        s = New StringBuilder()
        For i As Int32 = 0 To m.Length() - 1
            Dim a() As Object = Nothing
            'use TypeOf Is operator to avoid late bind
            If TypeOf m(i) Is Object() AndAlso
               cast(Of Object())(m(i), a) Then
                k_assert(Not a Is Nothing)
                If array_size(a) > 0 Then
                    s.Append(patchup_error_msg(a))
                End If
            ElseIf Not m(i) Is Nothing Then
                s.Append(Convert.ToString(m(i)))
            End If
        Next
        Return Convert.ToString(s)
    End Function

    Public Sub k_raise_error(ByVal ParamArray m() As Object)
        If Not m Is Nothing Then
            write_console_error_line(patchup_error_msg(m))
        End If
    End Sub
End Module
